﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Enter.Entity;
using Enter.Common;
using Enter.BizLogic;
using Enter.Web.SystemAdmin;
namespace WebSystemAdmin.sys
{
    public partial class RoleEdit : PageBase
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            ListCtrlHelper.BindEnumOnListControl(ddl_Status, typeof(Sys_RoleEntity.EnumStatus));
            if (!IsPostBack)
            {
                if (Request.QueryString["ID"] != null)
                {
                    GetInfo();
                }
            }
        }

        private void GetInfo()
        {
            Sys_RoleBLLSub bll = new Sys_RoleBLLSub();
            Sys_RoleEntity model = bll.GetObjectByID(int.Parse(Request.QueryString["ID"]));
            if (model == null) return;
            txt_ID.Text = model.ID.ToString();
            txt_RoleName.Text = model.RoleName.ToString();
            txt_Memo.Text = model.Memo.ToString();
            txt_Rights.Text = model.Rights.ToString();
            this.ddl_Status.Items.FindByValue(((byte)model.Status).ToString()).Selected = true;
        }

        protected void btnApply_Click(object sender, EventArgs e)
        {
            Sys_RoleEntity model = new Sys_RoleEntity();
            Sys_RoleBLLSub bll = new Sys_RoleBLLSub();
            if (Request.QueryString["ID"] != null)
            {
                model.ID = int.Parse(Request.QueryString["ID"]);
            }
            model.RoleName = txt_RoleName.Text;
            model.Memo = txt_Memo.Text;
            model.Rights = txt_Rights.Text;
            model.Status = (Sys_RoleEntity.EnumStatus)byte.Parse(ddl_Status.SelectedValue);
            if (bll.Save(model))
            {
                Utils.throwErrorGotoURL("添加成功", "RoleList.aspx");
            }
            else
            {
                Utils.ShowMessage("添加失败");
            }
        }
    }
}
